/*
 * TempAlarm.c
 *
 *  Created on: 2021年5月23日
 *      Author: Rupert
 */

#include "TempAlarm.h"

#include "Temperature.h"
#include "Buzzer.h"
#include "ScreenUI.h"

void TempAlarm(void)
{
	float Temp, TempLimit;
	Temp = getTemperature();
	TempLimit = getTempLimit();

	static uint8_t time_count = 0;
	if (Temp > TempLimit && Temp < 300)
	{
		setAlarmFlag();
		time_count = 5000 / TEMP_ALARM_RUN_INTERVAL_MS;
		addAlarmLog(Temp);
	}
	else
	{
		resetAlarmFlag();
	}
	if (getAlarmFlag() == 1)
	{
		Buzzer_TurnOn();
	}
	else if (getAlarmFlag() == 0 && time_count == 0)
	{
		Buzzer_TurnOff();
	}
	else
	{
		time_count--;
	}
}
